/*
 * BuildingAspect.cpp
 *
 *  Created on: Oct 27, 2008
 *      Author: Ryan
 */

#include "BuildingAspect.h"

#include "../../Logger.h"

namespace OOInterface
{

BuildingAspect::BuildingAspect(  float _maxHeight, float _minDepth, float _maxDepth ):
	_maxHeightDiff( _maxHeight ), _minWaterDepth( _minDepth ), _maxWaterDepth( _maxDepth )
{
}

BuildingAspect::~BuildingAspect()
{
}

bool BuildingAspect::canBuildAt( const GameMap& map, const Point3f loc, const Direction facing ) const
{
	int xSize = getParentUnit()->getXSize();
	int zSize = getParentUnit()->getZSize();

	for( unsigned int x = loc.getX() - xSize/2; x < loc.getX() + xSize; ++x )
		for( unsigned int y = loc.getZ() - zSize/2; y < loc.getZ() + zSize; ++y )
		{
			if( x < 0 || x > map.getWidth() || y < 0 || y > map.getHeight() )
				return false;

			float elevation = map.getElevation( x, y );
			if( elevation > _minWaterDepth || elevation < _maxWaterDepth  )
				return false;
		}

	return true;
}


}
